﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlyingAPI;
using System.Net;
using FlickrNet;

/*

namespace TagSpider
{
    class TagDownloadController
    {
        public enum TagDownloadStatus { STATUS_STOP, STATUS_PAUSE, STATUS_WORKING };

        LogAppend WritelnLog;
        
        public TagDownloadController(LogAppend g, TagDownloadLog downloadLog, int nMaxThreadNum)
        {
            m_nMaxThreadNum = nMaxThreadNum;
            m_downloadLog = downloadLog;
            WritelnLog = g;

            // 初始化下载线程
            m_listThreads = new List<TagDownloadThread>();
            for (int i = 0; i < nMaxThreadNum; i++)
            {
                TagDownloadThread newThread = new TagDownloadThread(g, downloadLog, this);
                m_listThreads.Add(newThread);
            }

            // 初始化状态
            m_DownloadStatus = TagDownloadStatus.STATUS_STOP;
        }

        public void start(int nThreadNum, String url)
        {
            m_nThreadNum = nThreadNum;
            for (int i = 0; i < m_nThreadNum; i++)
            {
                m_listThreads[i].Url = url;
                m_listThreads[i].start();
            }

            // 设置开始时间
            m_downloadLog.setStartTime(DateTime.Now);

            // 启动完所有线程后，设置状态
            m_DownloadStatus = TagDownloadStatus.STATUS_WORKING;
        }

        public void pause()
        {
            for (int i = 0; i < m_listThreads.Count; i++)
                if(m_listThreads[i] != null)
                {
                    m_listThreads[i].pause();
                }

            // 停止或暂停后，累计操作时间
            m_downloadLog.addMoreTime(DateTime.Now);

            // 暂停完所有线程后，设置状态
            m_DownloadStatus = TagDownloadStatus.STATUS_PAUSE;
        }

        public void stop()
        {
            for (int i = 0; i < m_listThreads.Count; i++)
            if (m_listThreads[i] != null)
            {
                m_listThreads[i].stop();
            }

            // 停止或暂停后，累计操作时间
            m_downloadLog.addMoreTime(DateTime.Now);

            // 停止完所有线程后，设置状态
            m_DownloadStatus = TagDownloadStatus.STATUS_STOP;
        }

        public void resume()
        {
            for (int i = 0; i < m_listThreads.Count; i++)
            if (m_listThreads[i] != null)
            {
                m_listThreads[i].resume();
            }

            // 设置开始时间
            m_downloadLog.setStartTime(DateTime.Now);

            // 启动完所有线程后，设置状态
            m_DownloadStatus = TagDownloadStatus.STATUS_WORKING;
        }

        // 是否所有下载线程都不处于下载状态，
        // 主要是GetResponse()函数
        public bool allThreadNotDownloading()
        {
            bool result = true;
            for (int i = 0; i < m_listThreads.Count; i++)
            if (m_listThreads[i] != null)
            {
                if (m_listThreads[i].isDownloading())
                {
                    result = false;
                    break;
                }
            }
            return result;
        }

        public TagDownloadStatus getCurStatus()
        {
            return m_DownloadStatus;
        }

        public TagDownloadLog getDownloadLog()
        {
            return m_downloadLog;
        }

        private int m_nThreadNum = 0;
        private int m_nMaxThreadNum = 0;
        private List<TagDownloadThread> m_listThreads;
        private TagDownloadStatus m_DownloadStatus;
        private TagDownloadLog m_downloadLog;
    }
}
 */
